//
//  Extension_TQVedio.swift
//  TQMedia
//
//  Created by XieLB on 2018/9/21.
//  Copyright © 2018年 CocoaPods. All rights reserved.
//

import CTMediator

// 模块名称
let TQMediaModuleVedioName = "TuQiangMedia"
// 子模块名称（视频）
let TQVedioModuleName = "TQVedio"
// 播放接口
let TQVedioPlayVedio = "playVedio"
// 播放接口
let TQVedioStopVedio = "stopVedio"
// 下载视频接口
let TQDownloadVedio = "downloadVedio"
// 暂停下载视频接口
let TQPauseDownloadVedio = "pauseDownloadVedio"
// 暂停所有下载视频接口
let TQPauseAllDownloadVedio = "pauseAllDownloadVedio"


public extension CTMediator {
    
    
    /// 播放视频接口
    ///
    /// - Parameter filePath: 本地视频文件路径
    /// - Parameter frame: 视频frame
    /// - Parameter closer: 反回视频view回调
    func tq_playVedio(filePath: URL, frame: CGRect, closer: @escaping ((UIView) -> Void)) {
        let params = [
            kCTMediatorParamsKeySwiftTargetModuleName: TQMediaModuleVedioName,
            "filePath": filePath,
            "frame": frame,
            "closer": closer
            ] as [String : Any]
        performTarget(TQVedioModuleName, action: TQVedioPlayVedio, params: params, shouldCacheTarget: false)
    }
    
    /// 停止播放视频接口
    func tq_stopVedio() {
        let params = [
            kCTMediatorParamsKeySwiftTargetModuleName: TQMediaModuleVedioName
            ] as [String : Any]
        performTarget(TQVedioModuleName, action: TQVedioStopVedio, params: params, shouldCacheTarget: false)
    }

    /// 下载视频接口
    ///
    /// - Parameter downloadUrl: 视频路径
    /// - closer: 回调
    func tq_downloadVedio(downloadUrl: String, closer: @escaping ((Dictionary<String, Any>) -> Void)) {
        let params = [
            kCTMediatorParamsKeySwiftTargetModuleName: TQMediaModuleVedioName,
            "downloadUrl": downloadUrl,
            "closer": closer
            ] as [String : Any]
        performTarget(TQVedioModuleName, action: TQDownloadVedio, params: params, shouldCacheTarget: false)
    }
    
    /// 暂停下载视频接口
    ///
    /// - Parameter downloadUrl: 视频路径
    func tq_pauseDownloadVedio(downloadUrl: String) {
        let params = [
            kCTMediatorParamsKeySwiftTargetModuleName: TQMediaModuleVedioName,
            "downloadUrl": downloadUrl
        ]
        performTarget(TQVedioModuleName, action: TQPauseDownloadVedio, params: params, shouldCacheTarget: false)
    }
    
    /// 暂停所有下载视频接口
    ///
    ///   - isResfreshCancleDownload: 是否为下拉刷新暂停
    ///   - closer: 回调
    func tq_pauseAllDownloadVedio(isResfreshCancleDownload: Bool, closer: @escaping (() -> Void)) {
        let params = [
            kCTMediatorParamsKeySwiftTargetModuleName: TQMediaModuleVedioName,
            "isResfreshCancleDownload": isResfreshCancleDownload,
            "closer": closer
            ] as [String : Any]
        performTarget(TQVedioModuleName, action: TQPauseAllDownloadVedio, params: params, shouldCacheTarget: false)
    }
}

